package demo2;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 沈明月
 * Date: 2023-01-03
 * Time: 16:04
 */

//一个类可以实现多个接口
//撇开了类型
//重写的快捷键：alt+enter
/*
abstract class Animal{
    public String name;

    public Animal(String name){
        this.name = name;
    }
}

interface IRunning{
    public void run();
}
interface ISwimming{
    public void swim();
}
interface IFly{
    public void fly();
}

class Dog extends Animal implements IRunning{//必须是先继承再实现接口
    public Dog(String name){
        super(name);
    }
    public void run(){
        System.out.println(name+" 正在跑！");
    }
}

class Fish extends Animal implements ISwimming{
    public Fish(String name){
        super(name);
    }
    public void swim(){
        System.out.println(name+"正在游泳！");
    }
}

class Bird extends Animal implements IFly{
    public Bird(String name){
        super(name);
    }
    public void fly(){
        System.out.println(name+"正在飞！");
    }
}

class Duck extends Animal implements IRunning,IFly,ISwimming{//实现了多个接口，Java是单继承的，不能继承多个
    public Duck(String name){
        super(name);
    }

    public void run(){
        System.out.println(name+" 正在跑！");
    }
    public void swim(){
        System.out.println(name+"正在游泳！");
    }
    public void fly(){
        System.out.println(name+"正在飞！");
    }
}

public class Test {
    public static void walk(IRunning iRunning){
        iRunning.run();
    }

    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void main(String[] args) {
        walk(new Dog("旺财"));
        walk(new Duck("唐老鸭"));
        System.out.println("===========");
        swim(new Fish("七秒"));
        swim(new Duck("小唐"));
    }
}
*/


abstract class Animal{
    public String name;

    public Animal(String name) {
        this.name = name;
    }
}

interface IRunning{//跑步
    void run();
}

interface ISwimming{//游泳
    void swim();
}

interface IFly{//飞
    void fly();
}

class Dog extends Animal implements IRunning{//先继承再实现接口
    public Dog(String name) {
        super(name);
    }
    public void run(){
        System.out.println(name+" 正在跑步（Dog版）");
    }
}
class Frog extends Animal implements ISwimming{
    public Frog(String name) {
        super(name);
    }
    public void swim(){
        System.out.println(name+" 正在游泳（Frog版）");
    }
}

class Bird extends Animal implements IRunning,ISwimming,IFly{//一个类实现多个接口（用逗号隔开）
    public Bird(String name) {
        super(name);
    }
    public void run(){
        System.out.println(name+" 正在跑步（Bird版）");
    }
    public void swim(){
        System.out.println(name+" 正在游泳（Bird版）");
    }
    public void fly(){
        System.out.println(name+" 正在飞（Bird版）");
    }
}
public class Test {
    public static void run(IRunning iRunning){
        iRunning.run();
    }

    public static void swim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void fly(IFly iFly){
        iFly.fly();
    }
    public static void main(String[] args) {
        run(new Dog("小狗"));

        System.out.println("========");

        swim(new Frog("小青蛙"));

        System.out.println("========");

        run(new Bird("小鸟"));
        swim(new Bird("小鸟"));
        fly(new Bird("小鸟"));
    }
}

